<template>
  <div id="app">
    <div class="productName">
      编号: <input type="text" v-model="id">
      品牌名称:<input type="text" v-model="name">
    </div>
    <button @click="create">生成</button>
    <table class="tb">
      <tr>
        <th>编号</th>
        <th>品牌名称</th>
        <th>创立时间</th>
        <th>操作</th>
      </tr>
      <!-- 循环渲染的元素tr -->
      <tr v-for="(vehicle,ind) in list" :key= "ind">
        <td>{{vehicle.id}}</td>
        <td>{{vehicle.name}}</td>
        <td>{{vehicle.time}}</td>
        <td>
          <button @click="dal(ind)">删除</button>
        </td>
      </tr>
      <tr>
        <td colspan="4"  v-if="list.length === 0">没有数据咯~</td>
      </tr>
    </table>
  </div>
</template>

<script>
import moment from 'moment'
export default {
  data () {
    return {
      list: [
        { id: 1, name: '奔驰', time: '2020-08-01' },
        { id: 2, name: '宝马', time: '2020-08-02' },
        { id: 3, name: '奥迪', time: '2020-08-03' }
      ],
      id: '',
      name: '',
      nuk: ''
    }
  },
  methods: {
    dal (ind) {
      this.list.splice(ind, 1)
    },
    create () {
      this.list.push({ id: this.id, name: this.name, time: moment().format('YYYY-MM-DD') })
    }

  }
}
</script>

<style>
.productName {
  display: inline-block;
  margin-right: 38px;
}
#app {
  width: 600px;
  margin: 10px auto;
}

.tb {
  border-collapse: collapse;
  width: 100%;
}

.tb th {
  background-color: #0094ff;
  color: white;
}

.tb td,
.tb th {
  padding: 5px;
  border: 1px solid black;
  text-align: center;
}

.add {
  padding: 5px;
  border: 1px solid black;
  margin-bottom: 10px;
}
</style>
